#!/bin/bash

# Copyright 2020 Jeff Cliff
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# obviously you want to change this
DBDIR=/home/themusicgod1/TDL

RED="\x1343"
USERID=$1
HOW_SLOW_IS_SPC=`grep -i 'HOW_SLOW_IS' ~/tools/deal_with_users.sh | grep -i '=' | awk -F'=' '{print $2}'`
#echo "SPC IS THIS SLOW" $HOW_SLOW_IS_SPC
BROWSER="chromium"
TEMPFILE=`mktemp`
sleep $HOW_SLOW_IS_SPC;
toot unfollow $USERID;
if [ $? == 0 ];
then
 #echo "success";
 howFar.sh $USERID > $TEMPFILE

 cat $TEMPFILE | grep update ;
 if [ $? == 0 ];
 # we have an existing user
 then
   cat $TEMPFILE
 else
#   cat $TEMPFILE
LINEME=`cat $TEMPFILE | grep -i insert | awk -F ',' '{print $1 "," $2 "," 420 "," $4 "," $5 "," $6}'`
echo sqlite3 $DBDIR/urls.db -line "$LINEME"
sqlite3 $DBDIR/urls.db -line "$LINEME"

#   $BROWSER "https://soap.shitposter.club/$USERID" &
 fi
else
 setterm --foreground red
 echo "!! failure !!";
 echo "!! run this manually !!"
 howFar.sh $USERID | grep -i 'insert'
 setterm --foreground default
 exit 1;
fi
